﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseData.UI;
using TaxEntity.User;
using TaxBiz.User;

namespace Admin.User
{
    public partial class ModifyPwd : BaseCommon.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!HasPower())
            {
                Jscript.AlertAndGoBack("您权限不足，不能操作");
                return;
            }
            string action = PageContext.GetRequest("action");
            if (!string.IsNullOrEmpty(action))
            {
                this.ModifyUserPwd();
            }
        }

        protected void ModifyUserPwd()
        {
            string oldPwd = PageContext.GetRequest("txtOldPwd");
            string newPwd = PageContext.GetRequest("txtNewPwd");
            string newPwdAgain = PageContext.GetRequest("txtNewPwdAgain");

            //UserData ud2 =  null;
            //ud2.Exists("");

            if (newPwd != newPwdAgain)
            {
                Jscript.AlertAndGoBack("您两次输入的新密码不一致");
                return;
            }
            UserBiz ud = new UserBiz();
            if (ud.GetEncryptPassword(oldPwd) != UserLogin.Pwd)
            {
                Jscript.AlertAndGoBack("旧密码输入错误，请重新输入");
                return;
            }
            UserEntity ue = new UserEntity();
            ue.UserId = UserID;
            ue.Pwd = ud.GetEncryptPassword(newPwd);
            ue.AddTime = DateTime.Now;
            if (ud.Update(ue, UserLogin))
            {
                Jscript.AlertAndRedirect("密码修改成功", "ModifyPwd.aspx");
            }
            else
            {
                Jscript.AlertAndGoBack("密码修改失败");
                return;
            }
        }
    }
}